function preprocess() {
//for debugging  echo('if(length(grep("Rcphsoc",searchpaths()))>0) detach("package:Rcphsoc")\n');
  echo('require(Rcphsoc)\n');
}

function calculate() {
  echo('t1 <- Sys.time()\n')
  
  function basename(url) {
    var fileName = url.substring(url.lastIndexOf('/') + 1);
    var dot = fileName.lastIndexOf('.');
    return dot == -1 ? fileName : fileName.substring(0, dot);
  }
  var infile_str,save_robj_str,save_varlist_str,save_stata_str,dta_replace_str,save_csv_str,out_file_str,out_dir_str,source_enc_str,target_enc_str,selectEncoding;
  
  //get values from dialog
  selectEncoding_str = getValue("selectEncoding");
  infile_str       = 'spss_file_path="' + getValue("spss_sav") + '"';
  save_robj_str    = ",\n           save_robj="    + getValue("save_robj");
  save_varlist_str = ",\n           save_varlist=" + getValue("save_varlist");
  save_stata_str   = ",\n           save_stata="   + getValue("save_stata");
  dta_replace_str  = ",\n           dta_replace="  + getValue("dta_replace");
  save_csv_str     = ",\n           save_csv="     + getValue("save_csv");
  out_file_str     = ",\n           out_filename="  + '"' + getValue("out_filename") + '"';
  out_dir_str      = ",\n           out_dirname="   + '"' + getValue("out_dirname") + '"';
  if(!getValue("selectEncoding"))
  {
    source_enc_str   = ",\n           source_enc=''";
    target_enc_str   = ",\n           target_enc=''";
  }
  else
  {
    source_enc_str   = ",\n           source_enc="    + '"' + getValue("source_enc") + '"';
    target_enc_str   = ",\n           target_enc="    + '"' + getValue("target_enc") + '"';
  }
  echo("res <- cphsoc_convert_from_spss(" + infile_str + save_robj_str + save_varlist_str + save_stata_str + dta_replace_str + save_csv_str + out_file_str + out_dir_str + source_enc_str + target_enc_str +")\n");
  echo("rk.print(paste(res,collapse='<br />',sep=''))\n");
  echo("rk.print(Sys.time() - t1)\n")



//==================================
}
